<template>
	<view>
		<view class="mycoupon-tab">
			<view class="mycoupon-tab-item" @click="tabClick(1)">
				商品券
				<text v-if="activeIndex===1" class="tab-line"></text>
			</view>
			<view class="mycoupon-tab-item" @click="tabClick(2)">
				服务券
				<text v-if="activeIndex===2" class="tab-line"></text>
			</view>
		</view>
		<view class="mycoupon-info">
			<text @click="activeInfoClick(1)" class="mycoupon-info-item"
				:class="{'mycoupon-info-item-active':activeInfoIndex===1}">未使用</text>
			<text @click="activeInfoClick(2)" class="mycoupon-info-item"
				:class="{'mycoupon-info-item-active':activeInfoIndex===2}">已使用</text>
			<text @click="activeInfoClick(3)" class="mycoupon-info-item"
				:class="{'mycoupon-info-item-active':activeInfoIndex===3}">已过期</text>
		</view>
		<view class="mycoupon-coupon">
			<view class="mycoupon-coupon-item" v-for="item in couponlist">
				<view class="mycoupon-coupon-item-left">
					<text class="mycoupon-coupon-item-left_top"><text
							class="fontSize26">{{item.percent&&item.percent.split('.')[0]}}</text>.{{item.percent&&item.percent.split('.')[1]}}折</text><br />
					<text class="mycoupon-coupon-item-left_btm">{{item.usercondition}}</text>
				</view>
				<view class="mycoupon-coupon-item-right">
					<text class="mycoupon-coupon-item-right_info"><text
							class="mycoupon-coupon-item-right_infoRed">全渠道券</text><text>{{item.name}}</text></text><br />
					<text class="mycoupon-coupon-item-right_time">{{item.time}}</text>
					<button class="mycoupon-coupon-item-right_btn" type="default">去使用</button>
				</view>
			</view>

		</view>
		<view class="mycoupon-btn">
			<text>领取更多好券</text>

		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				activeIndex: 1,
				activeInfoIndex: 1,
				couponData: {
					// 商品券
					goods: {
						// 未使用
						notUsed: [{
								percent: "8.8",
								usercondition: '满1元可用',
								name: "小程序新客福利券（88折）",
								time: '2021.08.26 15:44:57-2021.09.02 23:59:59'
							},
							{
								percent: "1.8",
								usercondition: '满20元可用',
								name: "小程序新客福利券（18折）",
								time: '2021.08.26 15:44:57-2021.09.02 23:59:59'
							}, {
								percent: "8.8",
								usercondition: '满1元可用',
								name: "小程序新客福利券（88折）",
								time: '2021.08.26 15:44:57-2021.09.02 23:59:59'
							},
							{
								percent: "1.8",
								usercondition: '满20元可用',
								name: "小程序新客福利券（18折）",
								time: '2021.08.26 15:44:57-2021.09.02 23:59:59'
							}, {
								percent: "8.8",
								usercondition: '满1元可用',
								name: "小程序新客福利券（88折）",
								time: '2021.08.26 15:44:57-2021.09.02 23:59:59'
							},
							{
								percent: "1.8",
								usercondition: '满20元可用',
								name: "小程序新客福利券（18折）",
								time: '2021.08.26 15:44:57-2021.09.02 23:59:59'
							}
						],
						// 已使用
						used: [],
						// 已过期
						expired: [{
								percent: "8.8",
								usercondition: '满1元可用',
								name: "小程序新客福利券（88折）",
								time: '2021.08.26 15:44:57-2021.09.02 23:59:59'
							},
							{
								percent: "1.8",
								usercondition: '满20元可用',
								name: "小程序新客福利券（18折）",
								time: '2021.08.26 15:44:57-2021.09.02 23:59:59'
							}
						]
					},
					// 服务券
					server: {
						// 未使用
						notUsed: [{
							percent: "8.8",
							usercondition: '满1元可用',
							name: "小程序新客福利券（88折）",
							time: '2021.08.26 15:44:57-2021.09.02 23:59:59'
						}, ],
						// 已使用
						used: [],
						// 已过期
						expired: []
					}

				},
				couponlist: []
			}
		},
		created() {
			this.couponlist = this.couponData.goods.notUsed;
		},
		methods: {
			tabClick(index) {
				this.activeIndex = index
				this.activeInfoIndex = 1
				if(this.activeIndex===1){
					this.couponlist = this.couponData.goods.notUsed
				}else{
					this.couponlist = this.couponData.server.notUsed
				}
			},
			activeInfoClick(index){
				this.activeInfoIndex = index;
				let data ;
				if(this.activeIndex===1){
					data = this.couponData.goods;
				}else{
					data = this.couponData.server;
				}
				if(this.activeInfoIndex===1){
					this.couponlist = data.notUsed;
				}else if(this.activeInfoIndex===2){
					this.couponlist = data.used;
				}else if(this.activeInfoIndex===3){
					this.couponlist = data.expired;
				}
			}
		}
	}
</script>

<style lang="scss">
	.mycoupon-tab {
		height: 40px;
		display: flex;
		justify-content: space-around;
		align-items: center;
		background: #fff;
		border-bottom: 1px solid #ccc;
		position: fixed;
		top: 0;
		left: 0;
		z-index: 11;
		width: 100%;

		.mycoupon-tab-item {
			position: relative;
			padding: 10px;
		}

		// &:before{
		// 	display: inline-block;
		// 	content: '213x';
		// 	width: 20px;
		// 	height: 2px;
		// 	position: absolute;
		// 	left: 0;
		// 	bottom: 0;
		// 	right: 0;
		// 	margin: auto;
		// 	background: red;
		// }
		.tab-line {
			position: absolute;
			left: 0;
			bottom: 0;
			right: 0;
			margin: auto;
			background: red;
			display: inline-block;
			width: 30px;
			height: 2px;
		}
	}

	.mycoupon-info {
		height: 40px;
		line-height: 40px;
		background: #fff;
		padding: 0 7px;
		position: fixed;
		top: 40px;
		left: 0;
		width: 100%;
		z-index: 10;

		.mycoupon-info-item {
			padding: 2px 7px;
			border-radius: 18px;
			background-color: #ece8e8;
			margin-right: 20px;
			font-size: 14px;
		}

		.mycoupon-info-item-active {
			border: 1px solid red;
			color: red;
			background-color: #fff;
		}
	}

	.mycoupon-coupon {
		margin-top: 86px;

		.mycoupon-coupon-item {
			width: 96%;
			height: 100px;
			background: #fff;
			margin: 0 auto;
			margin-bottom: 10px;
			display: flex;
			justify-content: space-between;
			align-items: center;
			box-sizing: border-box;

			.mycoupon-coupon-item-left {
				width: 36%;
				height: 100%;
				text-align: center;
				line-height: 22px;
				box-sizing: border-box;
				padding-top: 25px;
				border-right: 1px dashed #ccc;

				.mycoupon-coupon-item-left_btm {
					font-size: 12px;
					color: #757474;
				}
			}

			.mycoupon-coupon-item-right {
				padding: 12px 5px;

				box-sizing: border-box;
				height: 100%;

				.mycoupon-coupon-item-right_info {
					color: #3a3636;
					font-size: 14px;

					.mycoupon-coupon-item-right_infoRed {
						color: red;
						border: 1px solid red;
						font-size: 12px;
						margin-right: 3px;
					}
				}

				.mycoupon-coupon-item-right_time {
					color: #a3a0a0;
					font-size: 12px;
				}

				.mycoupon-coupon-item-right_btn {
					font-size: 14px;
					float: right;
					width: 73px;
					height: 27px;
					line-height: 27px;
					text-align: center;
					background: red;
					color: #fff;
					margin-top: 10px;
					border-radius: 19px;
				}
			}
		}
	}

	.mycoupon-btn {
		width: 100%;
		height: 70px;
		position: fixed;
		background-color: #fff;
		bottom: 0;
		color: #fff;
		margin: 0 auto;
		left: 0;
		right: 0;
		text-align: center;

		uni-text {
			display: inline-block;
			width: 90%;
			height: 55px;
			line-height: 55px;
			background: red;
			border-radius: 31px;
			text-align: center;
			font-size: 20px;
			margin-top: 10px;
		}

	}
</style>
